<template>
  <common-table
    ref="table"
    :show-toolbar="false"
    @vue:mounted="() => $refs.table.load()"
    :fetch-params="paramsData"
    :fetch="getDataAsync"
    :columns="columns"
    style="width: 100%; height: 100%"
  >
    <template #index="{ index }">
      <span>{{ index + 1 }}</span>
    </template>
  </common-table>
</template>

<script>
import CommonTable from '@gis/lib/components/vex-table/index.vue';
export default {
  name: 'heartrate-table',
  components: { CommonTable },
  props: {
    data: { type: Object, default: () => ({}) },
  },
  data() {
    return {
      columns: [
        {
          title: '手环设备号',
          dataIndex: 'imei',
          width: 100,
        },
        {
          title: '定位时间',
          dataIndex: 'time_begin',
          width: 90,
        },
        {
          title: '城市',
          dataIndex: 'city',
        },
        {
          title: '地址',
          dataIndex: 'address',
        },
        {
          title: '经度',
          dataIndex: 'lon',
        },
        {
          title: '纬度',
          dataIndex: 'lat',
        },
        {
          title: '类型',
          dataIndex: 'type',
          customRender: (v) => ({ 0: 'GPS定位', 1: '基站定位' }[v]),
        },
        {
          title: '是否未响应',
          dataIndex: 'is_reply',
          customRender: (v) => (v ? '是' : '否'),
          width: 110,
        },
        {
          title: '是否轨迹',
          dataIndex: 'is_track',
          customRender: (v) => (v ? '是' : '否'),
          width: 90,
        },
      ],
    };
  },
  computed: {
    paramsData() {
      return {
        people_id: this.data.people_id,
      };
    },
  },
  methods: {
    async getDataAsync(params) {
      const res = await this.$axios.get('/xw-microservice/xw-actual-data/v3/bracelet/location/page', {
        params,
      });
      const data = res.data || {};
      return { data: data.list, total: data.count };
    },
  },
};
</script>

<style scoped></style>
